using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Easy.Geo.Kml
{
    public abstract class Feature : Object
    {
        public Feature()
            :base()
        {            
            this._open = KBool.False;
            this._visibility = KBool.True;            
        }
        public Feature(string name):this()
        {
            this._name = name;            
        }
        public Feature(string id, string name, KBool visibility, string address, 
            string description, string styleUrl, ExtendedData ExtendedData, KBool open):base(id)
        {            
            this._name = name;
            this._visibility = visibility;
            this._address = address;
            this._description = description;
            this._styleUrl = styleUrl;
            this._ExtendedData = ExtendedData;
            this._open = open;            
        }

        public Feature(string name, KBool visibility, KBool open)
            : this(name)
        {
            this._name = name;
            this._visibility = visibility;
            this._open = open;
        }

        private string _name;
        [XmlElement(ElementName="name")]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        private KBool _visibility;
        [XmlElement(ElementName = "visibility")]
        public KBool Visibility
        {
            get { return _visibility; }
            set { _visibility = value; }
        }
        private string _address;
        [XmlElement(ElementName = "address")]
        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }
        private string _description;        
        [XmlIgnore()]
        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }
        private string _styleUrl;
        [XmlElement(ElementName = "styleUrl")]
        public string StyleUrl
        {
            get { return _styleUrl; }
            set { _styleUrl = value; }
        }
        private ExtendedData _ExtendedData;
        [XmlElement(ElementName = "ExtendedData", Type=typeof(ExtendedData))]
        public ExtendedData ExtendedData
        {
            get { return _ExtendedData; }
            set { _ExtendedData = value; }
        }

        private KBool _open;
        [XmlElement(ElementName = "open")]
        public KBool Open
        {
            get { return _open; }
            set { _open = value; }
        }
        private StyleMap _StyleMap;
        [XmlElement(ElementName = "StyleMap")]
        public StyleMap StyleMap
        {
            get { return this._StyleMap; }
            set { this._StyleMap = value; }
        }        
        public ExtendedData GetExtendedData()
        {
            if (this._ExtendedData == null)
            {
                this._ExtendedData = new ExtendedData();
            }
            return this._ExtendedData;
        }

        public Snippet GetSnippet()
        {
            if (this._Snippet == null)
            {
                this._Snippet = new Snippet();
            }
            return this._Snippet;
        }

        public Data AddData(string name, string value)
        {
            return this.GetExtendedData().AddData(name, value);
        }

        public Data AddData(string name, string displayName, string value)
        {
            return this.GetExtendedData().AddData(displayName, name, value);            
        }

        public void AddData(Data data)
        {
            this.GetExtendedData().AddData(data);
        }

        private Snippet _Snippet;

        public Snippet Snippet
        {
            get { return _Snippet; }
            set { _Snippet = value; }
        }
        [XmlElement(ElementName="description")]
        public XmlCDataSection XmlDescription
        {
            get
            {
                XmlDataDocument doc = new XmlDataDocument();
                XmlCDataSection cdata = doc.CreateCDataSection(this._description);
                return cdata;
            }
            set
            {
                this._description = value.Value;
            }
        }
    }
}
